package figure8.GUI;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JProgressBar;

import figure8.Controller;
import figure8.DownloadingTrack;
import figure8.Track;
import figure8.events.DownloadFinishedEvent;
import figure8.events.DownloadProgressListener;
import figure8.events.DownloadProgressedEvent;

public class DownloadingTrackProgressPanel extends JPanel implements DownloadProgressListener {
	private Controller controller;
	private JProgressBar progress;
	private DownloadingTrack track;
	
	public DownloadingTrackProgressPanel(Controller controller, DownloadingTrack track) {
		this.track = track;
		this.controller = controller;
		this.progress = new JProgressBar(0, track.getSize());
		track.addDownloadListener(this);
		this.add(this.progress, BorderLayout.CENTER);
		this.progress.setValue(0);
	}

	@Override
	public void downloadProgressed(DownloadProgressedEvent event) {
		this.progress.setValue((int) (event.getProgress() * this.track.getSize()));
		this.controller.getWindow().getFrame().pack();
		//System.out.println("Download progress " + event.getProgress());
	}

	@Override
	public void downloadFinished(DownloadFinishedEvent event) {
		System.out.println("Download finished");
	}
}
